// page/member/newly.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    index: 0,
    course: ["建设银行", "民生银行", "交通银行"],
    name:'',
    card:'',
    tpl:'',
    bank:'',
    banks:'建设银行'
  },

  bindPickerChange: function (e) {
    this.setData({
      index: e.detail.value,
      banks: e.currentTarget.dataset.banks,
    })
  },
  name:function(e){
    this.setData({
      name: e.detail.value,
    })
  },
  card:function(e){
    this.setData({
      card: e.detail.value,
    })
  },
  tpl: function (e) {
    this.setData({
      tpl: e.detail.value,
    })
  },
  bank: function (e) {
    this.setData({
      bank: e.detail.value,
    })
  },

  // onShow: function () {
  //   var app = getApp()
  //   var that = this;
  //   var uid = wx.getStorageSync('uid');
  //   // console.log(uid)
  //   wx.request({
  //     url: app.globalData.host + '&g=App&m=User&a=add_card',
  //     data: { uid: uid },
  //     header: {
  //       'content-type': 'application/json'
  //     },
  //     success: function (res) {
  //       console.log(res.data)
  //       that.setData({
  //         money: res.data.money
  //       })
  //     }
  //   })
  // },
  submid:function(){
    var app = getApp()
    var that = this;
    var uid = wx.getStorageSync('uid');
    var name = that.data.name;
    var card = that.data.card;
    var tpl = that.data.tpl;
    // 银行卡号
    var bank = that.data.bank;
    var banks = that.data.banks;
    // 银行卡正则
    var regex = /^(998801|998802|622525|622526|435744|435745|483536|528020|526855|622156|622155|356869|531659|622157|627066|627067|627068|627069)\d{10}$/;
    // 电话正则
    var regu = /^(13[0-9]|15[0-9]|18[0-9]|147|145|149|170|171|173|175|176|177|178)\d{8}$/;
    // 姓名验证
    var reguu = "^[\\u4E00-\\u9FA5\\uF900-\\uFA2D]+$";
    var re = new RegExp(reguu);
    // console.log(uid)
    if (name.length < 1 || card.length < 1 || tpl.length < 1 || bank.length < 1){
      wx.showModal({
        title: '提示',
        content: '请填写完整信息',
        showCancel: false,
        // mask:true,
        duration: 2000,
      })
    }
    else if (!re.test(name)) {
      wx.showModal({
        title: '提示',
        content: '请填写正确姓名',
        showCancel: false,
        // mask:true,
        duration: 2000,
      })
    } 
    else if (!card || !/^\d{6}(18|19|20)?\d{2}(0[1-9]|1[12])(0[1-9]|[12]\d|3[01])\d{3}(\d|X)$/i.test(card)) {
      wx.showModal({
        title: '提示',
        content: '请填写正确身份证',
        showCancel: false,  
        // mask:true,
        duration: 2000,
      })
    } 
    else if (!regu.test(tpl)) {
      wx.showModal({
        title: '提示',
        content: '请填写正确手机号',
        showCancel: false,
        // mask:true,
        duration: 2000,
      })
    } 
    //  else if (!regex.test(bank)){
    //   wx.showModal({
    //     title: '提示',
    //     content: '请输入正确的银行卡',
    //     showCancel: false,
    //     // mask:true,
    //     duration: 2000,
    //   })
    // }
    else{
      wx.request({
        url: app.globalData.host + '&g=App&m=User&a=add_card',
        data: {
          uid: uid,
          userName: that.data.name,
          idCard: that.data.card,
          telphone: that.data.tpl,
          bankCard: that.data.bank,
          bankName: that.data.banks
        },
        header: {
          'content-type': 'application/json'
        },
        success: function (res) {
          console.log(res.data)
          that.setData({
            money: res.data.money
          })
          wx.showModal({
            title: '提示',
            content: '添加成功',
            showCancel: false,
            mask: true,
            success: function (res) {
              if (res.confirm) {
                wx.redirectTo({
                  url: '/page/member/bankcar',
                  data:{
                    uid: uid,
                    userName: that.data.name,
                    idCard: that.data.card,
                    telphone: that.data.tpl,
                    bankCard: that.data.bank,
                    bankName: that.data.banks
                  }
                })
              }
            }
          })
        }
         
      })
    }
    
  },
})